<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\model\AdminRoles;
use app\admin\validate\AdminValidate;
use think\facade\View;
use think\Request;

class Admins extends Common
{
    protected $modelClass = \app\admin\model\Admins::class;
    protected $withModel   = ['adminInfo'];
    protected $detailWithModel = ['role'];
    protected $validator   = AdminValidate::class;

    protected function setSearchWhereFilter(array &$params = []):void
    {
        parent::setSearchWhereFilter($params); // TODO: Change the autogenerated stub

        if (isset($params['search']) && !empty($params['search'])){
            $params['where'][] = ['admin_name|admin_email', 'like', '%' . $params['search'] . '%'];
        }

        if ( isset($params['is_check']) && $params['is_check'] > -1 ) {
            $params['where'][] = ['is_check', '=', $params['is_check']];
        }
    }

    public function detail()
    {
        View::assign('roles', AdminRoles::getInstance()->getSelectLists());

        return parent::detail(); // TODO: Change the autogenerated stub
    }

    public function delete(Request $request)
    {
        if ($request->param($this->model->getPk(), 0) == 1){
            return $this->errorJson('禁止删除操作！');
        }

        return parent::delete($request); // TODO: Change the autogenerated stub
    }

    public function export($file_name = '管理员', $title = [], $data = [])
    {
        parent::export($file_name, $title, $data); // TODO: Change the autogenerated stub
    }
}
